using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using EcsSiteDSTableAdapters;
namespace SiteECSWeb
{
    [DataObject(true)]
    public class LcompanyBLL
    {
        private LcompanyTableAdapter _LcompanyAdapter = null;

        protected LcompanyTableAdapter LcompanyAdapter
        {
            get
            {
                if (_LcompanyAdapter == null)
                {
                    _LcompanyAdapter = new LcompanyTableAdapter();
                }
                return _LcompanyAdapter;
            }

        }


        #region SelectLcompany
        //  Get All Lcompany Data//
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]

        public EcsSiteDS.LcompanyDataTable GetLcompanydata()
        {
            return LcompanyAdapter.GetLcompanyRowRankData();
        }



        // Get Lcompany data By Comp id //
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.LcompanyDataTable GetLcompanyByCompID(int Comp_id)
        {
            if (Comp_id <= 0)
            {
                return LcompanyAdapter.GetLcompanyRowRankData();

            }
            else
            {
                return LcompanyAdapter.GetLcompanyDataByLcompId(Comp_id);
            }
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.LcompanyDataTable GetLcompanyByCompEmail(string email)
        {
            return LcompanyAdapter.GetLcompanyDataByLcompEmail(email);
        }

        #endregion

        #region InsertLcompany
        //Insert Egyptian company to Lcompany//

        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public bool AddLcompany(string Comp_fulnmar, string Comp_smlnmar, string Comp_addrsar, string Comp_breifar,
            string Comp_fulnmen, string Comp_smlnmen, string Comp_addrsen, string Comp_breifen, string Comp_phne1,
            string Comp_phne2, string Comp_fax1, string Comp_fax2, string Comp_mobil1, string Comp_mobil2,
            string Comp_pscod, int Comp_comircod, string Comp_email1, string Comp_email2, string Comp_Wsite,
            string Comp_NumberEmp, string EstablishmentYear, int City_id, string Comp_logoPath,
            DateTime? EntryDate, int? Comp_Sector_id, string Comp_ProductRangeAr, string Comp_ProductRangeEn)
        {

            EcsSiteDS.LcompanyDataTable LcomapnyTable = new EcsSiteDS.LcompanyDataTable();
            EcsSiteDS.LcompanyRow LcompanyRow = LcomapnyTable.NewLcompanyRow();

            if (string.IsNullOrEmpty(Comp_smlnmar)) LcompanyRow.SetComp_smlnmarNull(); else LcompanyRow.Comp_smlnmar = Comp_smlnmar;
            if (string.IsNullOrEmpty(Comp_breifar)) LcompanyRow.SetComp_breifarNull(); else LcompanyRow.Comp_breifar = Comp_breifar;
            if (string.IsNullOrEmpty(Comp_fulnmen)) LcompanyRow.SetComp_fulnmenNull(); else LcompanyRow.Comp_fulnmen = Comp_fulnmen;
            if (string.IsNullOrEmpty(Comp_smlnmen)) LcompanyRow.SetComp_smlnmenNull(); else LcompanyRow.Comp_smlnmen = Comp_smlnmen;
            if (string.IsNullOrEmpty(Comp_addrsen)) LcompanyRow.SetComp_addrsenNull(); else LcompanyRow.Comp_addrsen = Comp_addrsen;
            if (string.IsNullOrEmpty(Comp_breifen)) LcompanyRow.SetComp_breifenNull(); else LcompanyRow.Comp_breifen = Comp_breifen;

            if (string.IsNullOrEmpty(Comp_phne1)) LcompanyRow.SetComp_phne1Null(); else LcompanyRow.Comp_phne1 = Comp_phne1;
            if (string.IsNullOrEmpty(Comp_fax1)) LcompanyRow.SetComp_fax1Null(); else LcompanyRow.Comp_fax1 = Comp_fax1;
            if (string.IsNullOrEmpty(Comp_mobil1)) LcompanyRow.SetComp_mobil1Null(); else LcompanyRow.Comp_mobil1 = Comp_mobil1;
            if (string.IsNullOrEmpty(Comp_email1)) LcompanyRow.SetComp_email1Null(); else LcompanyRow.Comp_email1 = Comp_email1;

            if (string.IsNullOrEmpty(Comp_phne2)) LcompanyRow.SetComp_phne2Null(); else LcompanyRow.Comp_phne2 = Comp_phne2;
            if (string.IsNullOrEmpty(Comp_fax2)) LcompanyRow.SetComp_fax2Null(); else LcompanyRow.Comp_fax2 = Comp_fax2;
            if (string.IsNullOrEmpty(Comp_mobil2)) LcompanyRow.SetComp_mobil2Null(); else LcompanyRow.Comp_mobil2 = Comp_mobil2;
            if (string.IsNullOrEmpty(Comp_pscod)) LcompanyRow.SetComp_pscodNull(); else LcompanyRow.Comp_pscod = Comp_pscod;
            if (string.IsNullOrEmpty(Comp_email2)) LcompanyRow.SetComp_email2Null(); else LcompanyRow.Comp_email2 = Comp_email2;
            if (string.IsNullOrEmpty(Comp_Wsite)) LcompanyRow.SetComp_WsiteNull(); else LcompanyRow.Comp_Wsite = Comp_Wsite;
            if (string.IsNullOrEmpty(EstablishmentYear)) LcompanyRow.SetEstablishmentYearNull(); else LcompanyRow.EstablishmentYear = EstablishmentYear;
            if (string.IsNullOrEmpty(Comp_NumberEmp)) LcompanyRow.SetComp_NumberEmpNull(); else LcompanyRow.Comp_NumberEmp = Comp_NumberEmp;
            if (string.IsNullOrEmpty(Comp_logoPath)) LcompanyRow.SetComp_logoPathNull(); else LcompanyRow.Comp_logoPath = Comp_logoPath;
            if (Comp_Sector_id == null) LcompanyRow.SetComp_Sector_idNull(); else LcompanyRow.Comp_Sector_id = Comp_Sector_id.Value;
            if (string.IsNullOrEmpty(Comp_ProductRangeAr)) LcompanyRow.SetComp_ProductRangeArNull(); else LcompanyRow.Comp_ProductRangeAr = Comp_ProductRangeAr;
            if (string.IsNullOrEmpty(Comp_ProductRangeEn)) LcompanyRow.SetComp_ProductRangeEnNull(); else LcompanyRow.Comp_ProductRangeEn = Comp_ProductRangeEn;


            LcompanyRow.Comp_fulnmar = Comp_fulnmar;
            LcompanyRow.Comp_addrsar = Comp_addrsar;
            //LcompanyRow.Comp_phne1 = Comp_phne1;
            //LcompanyRow.Comp_fax1 = Comp_fax1;
            //LcompanyRow.Comp_mobil1 = Comp_mobil1;
            //LcompanyRow.Comp_email1 = Comp_email1;
            LcompanyRow.Comp_comircod = Comp_comircod;

            LcompanyRow.City_id = City_id;

            LcomapnyTable.AddLcompanyRow(LcompanyRow);

            int rowsAffected = LcompanyAdapter.Update(LcomapnyTable);

            return rowsAffected == 1;
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Insert, false)]
        public int AddLcompany(string Comp_fulnmar, string Comp_fulnmen, string Comp_smlnmar,
            string Comp_smlnmen,
            string Comp_addrsar, string Comp_addrsen, int Comp_comircod, string EstablishmentYear,
            int City_id, string Comp_NumberEmp, string Comp_breifar, string Comp_breifen,
            int? Comp_Sector_id,
            string Comp_ProductRangeAr, string Comp_ProductRangeEn)
        {

            EcsSiteDS.LcompanyDataTable LcomapnyTable = new EcsSiteDS.LcompanyDataTable();
            EcsSiteDS.LcompanyRow LcompanyRow = LcomapnyTable.NewLcompanyRow();

            if (string.IsNullOrEmpty(Comp_smlnmar)) LcompanyRow.SetComp_smlnmarNull(); else LcompanyRow.Comp_smlnmar = Comp_smlnmar;

            if (string.IsNullOrEmpty(Comp_breifar)) LcompanyRow.SetComp_breifarNull(); else LcompanyRow.Comp_breifar = Comp_breifar;
            if (string.IsNullOrEmpty(Comp_fulnmen)) LcompanyRow.SetComp_fulnmenNull(); else LcompanyRow.Comp_fulnmen = Comp_fulnmen;
            if (string.IsNullOrEmpty(Comp_smlnmen)) LcompanyRow.SetComp_smlnmenNull(); else LcompanyRow.Comp_smlnmen = Comp_smlnmen;
            if (string.IsNullOrEmpty(Comp_addrsen)) LcompanyRow.SetComp_addrsenNull(); else LcompanyRow.Comp_addrsen = Comp_addrsen;
            if (string.IsNullOrEmpty(Comp_breifen)) LcompanyRow.SetComp_breifenNull(); else LcompanyRow.Comp_breifen = Comp_breifen;

            if (string.IsNullOrEmpty(EstablishmentYear)) LcompanyRow.SetEstablishmentYearNull(); else LcompanyRow.EstablishmentYear = EstablishmentYear;
            if (string.IsNullOrEmpty(Comp_NumberEmp)) LcompanyRow.SetComp_NumberEmpNull(); else LcompanyRow.Comp_NumberEmp = Comp_NumberEmp;
            if (Comp_Sector_id == null) LcompanyRow.SetComp_Sector_idNull(); else LcompanyRow.Comp_Sector_id = Comp_Sector_id.Value;
            if (string.IsNullOrEmpty(Comp_ProductRangeAr)) LcompanyRow.SetComp_ProductRangeArNull(); else LcompanyRow.Comp_ProductRangeAr = Comp_ProductRangeAr;
            if (string.IsNullOrEmpty(Comp_ProductRangeEn)) LcompanyRow.SetComp_ProductRangeEnNull(); else LcompanyRow.Comp_ProductRangeEn = Comp_ProductRangeEn;

            LcompanyRow.Comp_fulnmar = Comp_fulnmar;
            LcompanyRow.Comp_addrsar = Comp_addrsar;
            LcompanyRow.Comp_comircod = Comp_comircod;
            LcompanyRow.City_id = City_id;

            LcomapnyTable.AddLcompanyRow(LcompanyRow);

            int rowsAffected = LcompanyAdapter.Update(LcomapnyTable);

            return rowsAffected == 1 ? LcompanyRow.Comp_id : 0;
        }

        #endregion

        #region UpdateLcompany
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public bool UpdateLcompany(string Comp_fulnmar, string Comp_smlnmar, string Comp_addrsar,
            string Comp_breifar, string Comp_fulnmen, string Comp_smlnmen, string Comp_addrsen,
            string Comp_breifen, string Comp_phne1, string Comp_phne2, string Comp_fax1,
            string Comp_fax2, string Comp_mobil1, string Comp_mobil2, string Comp_pscod,
            int Comp_comircod, string Comp_email1, string Comp_email2, string Comp_Wsite,
            string Comp_NumberEmp, string EstablishmentYear, int City_id, string Comp_logoPath,
            DateTime? EntryDate, int? Comp_Sector_id, string Comp_ProductRangeAr, string Comp_ProductRangeEn, int Comp_id)
        {

            EcsSiteDS.LcompanyDataTable LcomapnyTable = LcompanyAdapter.GetLcompanyDataByLcompId(Comp_id);
            if (LcomapnyTable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.LcompanyRow LcompanyRow = LcomapnyTable[0];

            if (string.IsNullOrEmpty(Comp_smlnmar)) LcompanyRow.SetComp_smlnmarNull(); else LcompanyRow.Comp_smlnmar = Comp_smlnmar;
            if (string.IsNullOrEmpty(Comp_breifar)) LcompanyRow.SetComp_breifarNull(); else LcompanyRow.Comp_breifar = Comp_breifar;
            if (string.IsNullOrEmpty(Comp_fulnmen)) LcompanyRow.SetComp_fulnmenNull(); else LcompanyRow.Comp_fulnmen = Comp_fulnmen;
            if (string.IsNullOrEmpty(Comp_smlnmen)) LcompanyRow.SetComp_smlnmenNull(); else LcompanyRow.Comp_smlnmen = Comp_smlnmen;
            if (string.IsNullOrEmpty(Comp_addrsen)) LcompanyRow.SetComp_addrsenNull(); else LcompanyRow.Comp_addrsen = Comp_addrsen;
            if (string.IsNullOrEmpty(Comp_breifen)) LcompanyRow.SetComp_breifenNull(); else LcompanyRow.Comp_breifen = Comp_breifen;

            if (string.IsNullOrEmpty(Comp_phne2)) LcompanyRow.SetComp_phne2Null(); else LcompanyRow.Comp_phne2 = Comp_phne2;
            if (string.IsNullOrEmpty(Comp_fax2)) LcompanyRow.SetComp_fax2Null(); else LcompanyRow.Comp_fax2 = Comp_fax2;
            if (string.IsNullOrEmpty(Comp_mobil2)) LcompanyRow.SetComp_mobil2Null(); else LcompanyRow.Comp_mobil2 = Comp_mobil2;
            if (string.IsNullOrEmpty(Comp_pscod)) LcompanyRow.SetComp_pscodNull(); else LcompanyRow.Comp_pscod = Comp_pscod;
            if (string.IsNullOrEmpty(Comp_email2)) LcompanyRow.SetComp_email2Null(); else LcompanyRow.Comp_email2 = Comp_email2;
            if (string.IsNullOrEmpty(Comp_Wsite)) LcompanyRow.SetComp_WsiteNull(); else LcompanyRow.Comp_Wsite = Comp_Wsite;
            if (string.IsNullOrEmpty(EstablishmentYear)) LcompanyRow.SetEstablishmentYearNull(); else LcompanyRow.EstablishmentYear = EstablishmentYear;
            if (string.IsNullOrEmpty(Comp_NumberEmp)) LcompanyRow.SetComp_NumberEmpNull(); else LcompanyRow.Comp_NumberEmp = Comp_NumberEmp;
            if (string.IsNullOrEmpty(Comp_logoPath)) LcompanyRow.SetComp_logoPathNull(); else LcompanyRow.Comp_logoPath = Comp_logoPath;
            if (Comp_Sector_id == null) LcompanyRow.SetComp_Sector_idNull(); else LcompanyRow.Comp_Sector_id = Comp_Sector_id.Value;
            if (string.IsNullOrEmpty(Comp_ProductRangeAr)) LcompanyRow.SetComp_ProductRangeArNull(); else LcompanyRow.Comp_ProductRangeAr = Comp_ProductRangeAr;
            if (string.IsNullOrEmpty(Comp_ProductRangeEn)) LcompanyRow.SetComp_ProductRangeEnNull(); else LcompanyRow.Comp_ProductRangeEn = Comp_ProductRangeEn;


            LcompanyRow.Comp_fulnmar = Comp_fulnmar;
            LcompanyRow.Comp_addrsar = Comp_addrsar;
            LcompanyRow.Comp_phne1 = Comp_phne1;
            LcompanyRow.Comp_fax1 = Comp_fax1;
            LcompanyRow.Comp_mobil1 = Comp_mobil1;
            LcompanyRow.Comp_comircod = Comp_comircod;
            LcompanyRow.Comp_email1 = Comp_email1;
            LcompanyRow.City_id = City_id;

            int rowsAffected = LcompanyAdapter.Update(LcompanyRow);

            return rowsAffected == 1;
        }


        [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
        public bool UpdateLcompany(string Comp_fulnmar, string Comp_smlnmar, string Comp_addrsar,
            string Comp_breifar, string Comp_fulnmen, string Comp_smlnmen, string Comp_addrsen,
            string Comp_breifen, int Comp_comircod, 
            string Comp_NumberEmp, string EstablishmentYear, int City_id,
            int? Comp_Sector_id, string Comp_ProductRangeAr, string Comp_ProductRangeEn, int Comp_id)
        {

            EcsSiteDS.LcompanyDataTable LcomapnyTable = LcompanyAdapter.GetLcompanyDataByLcompId(Comp_id);
            if (LcomapnyTable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.LcompanyRow LcompanyRow = LcomapnyTable[0];

            if (string.IsNullOrEmpty(Comp_smlnmar)) LcompanyRow.SetComp_smlnmarNull(); else LcompanyRow.Comp_smlnmar = Comp_smlnmar;
            if (string.IsNullOrEmpty(Comp_breifar)) LcompanyRow.SetComp_breifarNull(); else LcompanyRow.Comp_breifar = Comp_breifar;
            if (string.IsNullOrEmpty(Comp_fulnmen)) LcompanyRow.SetComp_fulnmenNull(); else LcompanyRow.Comp_fulnmen = Comp_fulnmen;
            if (string.IsNullOrEmpty(Comp_smlnmen)) LcompanyRow.SetComp_smlnmenNull(); else LcompanyRow.Comp_smlnmen = Comp_smlnmen;
            if (string.IsNullOrEmpty(Comp_addrsen)) LcompanyRow.SetComp_addrsenNull(); else LcompanyRow.Comp_addrsen = Comp_addrsen;
            if (string.IsNullOrEmpty(Comp_breifen)) LcompanyRow.SetComp_breifenNull(); else LcompanyRow.Comp_breifen = Comp_breifen;

            if (string.IsNullOrEmpty(EstablishmentYear)) LcompanyRow.SetEstablishmentYearNull(); else LcompanyRow.EstablishmentYear = EstablishmentYear;
            if (string.IsNullOrEmpty(Comp_NumberEmp)) LcompanyRow.SetComp_NumberEmpNull(); else LcompanyRow.Comp_NumberEmp = Comp_NumberEmp;
            
            if (Comp_Sector_id == null) LcompanyRow.SetComp_Sector_idNull(); else LcompanyRow.Comp_Sector_id = Comp_Sector_id.Value;
            if (string.IsNullOrEmpty(Comp_ProductRangeAr)) LcompanyRow.SetComp_ProductRangeArNull(); else LcompanyRow.Comp_ProductRangeAr = Comp_ProductRangeAr;
            if (string.IsNullOrEmpty(Comp_ProductRangeEn)) LcompanyRow.SetComp_ProductRangeEnNull(); else LcompanyRow.Comp_ProductRangeEn = Comp_ProductRangeEn;


            LcompanyRow.Comp_fulnmar = Comp_fulnmar;
            LcompanyRow.Comp_addrsar = Comp_addrsar;            
            LcompanyRow.Comp_comircod = Comp_comircod;            
            LcompanyRow.City_id = City_id;

            int rowsAffected = LcompanyAdapter.Update(LcompanyRow);

            return rowsAffected == 1;
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
        public bool UpdateLcompany( string Comp_phne1, string Comp_phne2, string Comp_fax1,
            string Comp_fax2, string Comp_mobil1, string Comp_mobil2, string Comp_pscod,
            string Comp_email1, string Comp_email2, string Comp_Wsite,string Comp_logoPath,
            int Comp_id)
        {

            EcsSiteDS.LcompanyDataTable LcomapnyTable = LcompanyAdapter.GetLcompanyDataByLcompId(Comp_id);
            if (LcomapnyTable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.LcompanyRow LcompanyRow = LcomapnyTable[0];


            if (string.IsNullOrEmpty(Comp_phne2)) LcompanyRow.SetComp_phne2Null(); else LcompanyRow.Comp_phne2 = Comp_phne2;
            if (string.IsNullOrEmpty(Comp_fax2)) LcompanyRow.SetComp_fax2Null(); else LcompanyRow.Comp_fax2 = Comp_fax2;
            if (string.IsNullOrEmpty(Comp_mobil2)) LcompanyRow.SetComp_mobil2Null(); else LcompanyRow.Comp_mobil2 = Comp_mobil2;
            if (string.IsNullOrEmpty(Comp_pscod)) LcompanyRow.SetComp_pscodNull(); else LcompanyRow.Comp_pscod = Comp_pscod;
            if (string.IsNullOrEmpty(Comp_email2)) LcompanyRow.SetComp_email2Null(); else LcompanyRow.Comp_email2 = Comp_email2;
            if (string.IsNullOrEmpty(Comp_Wsite)) LcompanyRow.SetComp_WsiteNull(); else LcompanyRow.Comp_Wsite = Comp_Wsite;
            if (string.IsNullOrEmpty(Comp_logoPath)) LcompanyRow.SetComp_logoPathNull(); else LcompanyRow.Comp_logoPath = Comp_logoPath;

            LcompanyRow.Comp_phne1 = Comp_phne1;
            LcompanyRow.Comp_fax1 = Comp_fax1;
            LcompanyRow.Comp_mobil1 = Comp_mobil1;            
            LcompanyRow.Comp_email1 = Comp_email1;            
         
            int rowsAffected = LcompanyAdapter.Update(LcompanyRow);

            return rowsAffected == 1;
        }

        #endregion

        #region DeleteLcompany
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public bool DeleteLcomapny(int Comp_id)
        {
            EcsSiteDS.LcompanyDataTable LcomapnyTable = LcompanyAdapter.GetLcompanyDataByLcompId(Comp_id);
            if (LcomapnyTable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.LcompanyRow LcompanyRow = LcomapnyTable[0];

            System.IO.File.Delete(HttpContext.Current.Server.MapPath(Globals.Settings.UploadInfo.RootAttachFolder
                          + LcompanyRow.Comp_logoPath));

            int rowsAffected = LcompanyAdapter.Delete(Comp_id);
            return rowsAffected == 1;
        }

        #endregion
    }
}

